package com.shensi.adminCollect.controller.station;


import com.shensi.common.core.controller.BaseController;
import com.shensi.common.core.domain.AjaxResult;
import com.shensi.adminCollect.domain.station.*;
import com.shensi.adminCollect.domain.station.dto.MerAccEntryDto;
import com.shensi.adminCollect.service.station.CashReceiptsService;
import com.shensi.adminCollect.service.station.IStationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * (CashReceipts)表控制层
 *
 * @author makejava
 * @since 2023-04-18 14:17:26
 */
@Api(tags = "财务")
@RestController
@RequestMapping("/cashReceipts")
public class CashReceiptsController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private CashReceiptsService cashReceiptsService;


    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private IStationService stationService;
    @Value("${clearUrl}")
    private String clearUrl;


    /**
     * 现金分页查询
     *
     * @return 查询结果
     */
    @GetMapping("/queryByPage")
    @ApiOperation("现金收款分页")
    public AjaxResult queryByPage(Long id, String startingTime, String endTimeint, int page, int pageSize, String phoneNumber, Long stationId, Long enterpriseId) {
        if (Objects.isNull(stationId) && Objects.isNull(enterpriseId)) return AjaxResult.error("没有查看权限");
        return AjaxResult.success("查询成功", this.cashReceiptsService.queryByPage(id, startingTime, endTimeint, page, pageSize, phoneNumber, stationId, enterpriseId));
    }


    /**
     * 查询提现列表
     */
    @GetMapping("/queryNoInsensTrans")
    @ApiOperation("查询提现列表")
    public  Map<String, Object> queryNoInsensTrans(QueryNoInsensTransDTO queryNoInsensTransDTO) {
        Map<String, Object> result  =  cashReceiptsService.queryNoInsensTrans(clearUrl,queryNoInsensTransDTO);
        return result;
    }

    /**
     * 查询提现汇总
     */
    @GetMapping("/queryNoInsensTransSum")
    @ApiOperation("查询提现汇总")
    public  QueryNoInsensTransSumVO queryNoInsensTransSum(QueryNoInsensTransSumDTO queryNoInsensTransSumDTO) {
        QueryNoInsensTransSumVO result  =  cashReceiptsService.queryNoInsensTransSum(clearUrl,queryNoInsensTransSumDTO);
        return result;
    }

    /**
     *
     * 账户信息
     */
    @GetMapping("/listStationMerAccInfo")
    @ApiOperation("查询油站账户信息")
    public List<NoInsensAccInfoVO> listStationMerAccInfo() {
        List<NoInsensAccInfoVO> result  =  cashReceiptsService.listStationMerAccInfo(clearUrl);
        return result;
    }

    /**
     *
     * 取服务费
     */
    @PostMapping("/getServiceFee")
    @ApiOperation("取服务费")
    public AjaxResult getServiceFee(MerAccGetServiceFeeDTO merAccGetServiceFeeDTO) {
        Map<String, Object> result  =  cashReceiptsService.getServiceFee(clearUrl,merAccGetServiceFeeDTO);
        AjaxResult aresult = new AjaxResult(200,"成功",result);
        return aresult;
    }

    /**
     *
     * 查询商户账户余额
     */
    @PostMapping("/queryBalance")
    @ApiOperation("查询商户账户余额")
    public Map<String, Object> queryBalance(MerAccGetServiceFeeDTO merAccGetServiceFeeDTO) {
        Map<String, Object> result  =  cashReceiptsService.queryBalance(clearUrl,merAccGetServiceFeeDTO);
        return result;
    }

    /**
     *
     * 查询商户账户余额
     */
    @PostMapping("/getEntrySum")
    @ApiOperation("查询账户入账总额")
    public AjaxResult getEntrySum(@RequestBody MerAccEntryDto merAccEntryDto) {
        AjaxResult result  =  cashReceiptsService.getEntrySum(clearUrl,merAccEntryDto);
        return result;
    }


    /**
     *
     * 查询商户账户余额
     */
    @PostMapping("/cash")
    @ApiOperation("提现 S成功 T进行中 需用订单查询接口查询结果  E失败")
    public Map<String, Object> cash(MerAccGetServiceFeeDTO merAccGetServiceFeeDTO) {
        Map<String, Object> result  =  cashReceiptsService.cash(clearUrl,merAccGetServiceFeeDTO);
        return result;
    }



    /**
     * 新增数据
     *
     * @param cashReceipts 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    @ApiOperation("现金收款添加")
    public AjaxResult add(@RequestBody SysCashReceipts cashReceipts) {
        return AjaxResult.success("添加成功", this.cashReceiptsService.add(cashReceipts));
    }

    /**
     * 编辑数据
     *
     * @param cashReceipts 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    @ApiOperation("现金收款编辑")
    public AjaxResult edit(@RequestBody SysCashReceipts cashReceipts) {
        return AjaxResult.success("编辑成功", cashReceiptsService.edit(cashReceipts));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/deleteById")
    @ApiOperation("现金收款删除")
    public AjaxResult deleteById(@RequestBody List<Long> id) {
        return AjaxResult.success("删除成功", this.cashReceiptsService.deleteById(id));
    }

}

